from .. import db

import datetime


class AutoQuestion(db.Model):
    '''
    ques_tagid=3时
    status=1，题目OK，status=0.题目有问题（没有填空，填空是通过大模型给的答案回推填空，即大模型给的答案，都不在文本中）
    expert_status=1，大模型给的答案和实际问题答案一致
    expert_status=0，大模型给的答案和实际问题答案不一致
    '''
    __tablename__ = 'auto_question'
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text)
    output_chat = db.Column(db.Text)
    output_title = db.Column(db.Text)
    output_options = db.Column(db.JSON)
    output_answer = db.Column(db.Text)
    ques_tagid = db.Column(db.Integer)
    output_accur_count = db.Column(db.Integer)
    output_total_count = db.Column(db.Integer)
    expert_status = db.Column(db.SmallInteger, comment='0: except, 1: normal')
    status = db.Column(db.SmallInteger, comment='0: except, 1: normal')
    model_name = db.Column(db.String)
    datacollection_name = db.Column(db.String)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now())
    update_time = db.Column(db.DateTime, default=datetime.datetime.now())

    def get_ques_tag(self):
        return {1: '单选题', 2: '判断题', 3: '填空题', 4: '论述题'}.get(self.ques_tagid, '')

    def get_status(self):
        return {0: '题目有误', 1: '正常'}.get(self.status, '')

    def __repr__(self):
        return f"<AutoQuestion {self.id}:{self.output_title}>"
    

class SingleChoiceQuestion(db.Model):
    __tablename__ = 'single_choice_questions'
    
    id = db.Column(db.Integer, primary_key=True)
    ques_title = db.Column(db.Text, nullable=False)
    ques_options = db.Column(db.Text, nullable=False)  # 存储JSON字符串
    ques_answer = db.Column(db.String(1), nullable=False)
    ques_tagid = db.Column(db.Integer, nullable=False)
    status = db.Column(db.Integer, default=0)
    datacollection_name = db.Column(db.String(100))
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)


class FillBlankQuestion(db.Model):
    __tablename__ = 'fill_blank_questions'
    
    id = db.Column(db.Integer, primary_key=True)
    ques_title = db.Column(db.Text, nullable=False)  # 包含【】的文本片段
    ques_keywords = db.Column(db.Text, nullable=False)  # 存储JSON字符串格式的关键信息列表
    ques_tagid = db.Column(db.Integer, nullable=False, default=3)  # 3表示填空题
    status = db.Column(db.Integer, default=0)  # 0表示无效，1表示有效
    datacollection_name = db.Column(db.String(100))
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    

class MultiChoiceQuestion(db.Model):
    __tablename__ = 'multi_choice_questions'
    
    id = db.Column(db.Integer, primary_key=True)
    ques_title = db.Column(db.Text, nullable=False)  # 题目内容
    ques_options = db.Column(db.Text, nullable=False)  # 存储JSON字符串格式的选项
    ques_answer = db.Column(db.Text, nullable=False)  # 存储JSON字符串格式的答案列表
    ques_tagid = db.Column(db.Integer, nullable=False, default=2)  # 2表示多选题
    status = db.Column(db.Integer, default=0)  # 0表示无效，1表示有效
    datacollection_name = db.Column(db.String(100))
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)


class SubjectiveQuestion(db.Model):
    __tablename__ = 'subjective_questions'
    
    id = db.Column(db.Integer, primary_key=True)
    ques_title = db.Column(db.Text, nullable=False)  # 问题内容
    max_score = db.Column(db.Integer, nullable=False, default=10)  # 满分分值
    answers = db.Column(db.Text, nullable=False)  # 存储JSON字符串格式的答案及得分标准
    ques_tagid = db.Column(db.Integer, nullable=False, default=4)  # 4表示简答题
    status = db.Column(db.Integer, default=0)  # 0表示无效，1表示有效
    datacollection_name = db.Column(db.String(100))
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)


class DissertationQuestion(db.Model):
    __tablename__ = 'dissertation_questions'
    
    id = db.Column(db.Integer, primary_key=True)
    ques_title = db.Column(db.Text, nullable=False)  # 论述题题目内容
    max_score = db.Column(db.Integer, nullable=False, default=15)  # 满分分值，默认15分
    answers = db.Column(db.Text, nullable=False)  # 存储JSON字符串格式的答案及得分标准
    ques_tagid = db.Column(db.Integer, nullable=False, default=5)  # 5表示论述题
    status = db.Column(db.Integer, default=0)  # 0表示无效，1表示有效
    datacollection_name = db.Column(db.String(100))
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)


